import { BasicColumn, FormSchema } from '@/components/Table';
import { getTemplateList, getServerList } from '@/api/site/site';

export const columns: BasicColumn[] = [
  {
    title: '网站名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '域名',
    dataIndex: 'domain',
    width: 180,
  },
  {
    title: '服务器',
    dataIndex: 'server_name',
    width: 120,
  },
  {
    title: '模板',
    dataIndex: 'template_name',
    width: 120,
  },
  {
    title: '访问量',
    dataIndex: 'views',
    width: 80,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      return record.status === 10 ? '启用' : '禁用';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updated_at',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '站点名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'domain',
    label: '域名',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '启用', value: 10 },
        { label: '禁用', value: 20 },
      ],
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '站点名称',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'domain',
    label: '域名',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'template_id',
    label: '模板',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 24 },
    componentProps: {
      api: getTemplateList,
      resultField: 'list',
      labelField: 'name',
      valueField: 'id',
      immediate: true,
      params: { status: 10 },
    },
  },
  {
    field: 'server_id',
    label: '服务器',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 24 },
    componentProps: {
      api: getServerList,
      resultField: 'list',
      labelField: 'name',
      valueField: 'id',
      immediate: true,
      params: { status: 10 },
    },
  },
  {
    field: 'views',
    label: '访问量',
    component: 'InputNumber',
    required: true,
    defaultValue: 0,
    colProps: { span: 24 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 10,
    colProps: { span: 24 },
    componentProps: {
      options: [
        { label: '启用', value: 10 },
        { label: '禁用', value: 20 },
      ],
    },
  },
];
